package jiwei.service.annotation;

import jiwei.dao.UserDao;
import jiwei.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {
    @Autowired
    public UserDao dao; //注入dao

    public void add(User user) {
        dao.add(user);
    }

    @Transactional
    public void add_transacton() {
        dao.add(new User("12"));
        dao.add(new User("123"));
    }

    //--- protected，private ------
    @Autowired
    UserService userService_self;

    public void add_protected() {
        userService_self.add_tx_protected();
    }

    @Transactional
    protected void add_tx_protected() {
        dao.add(new User("12"));
        dao.add(new User("123"));
    }

    public void add_private() {
        userService_self.add_tx_private(dao);
    }

    //private的测试不能通过
    @Transactional
    private void add_tx_private(UserDao dao) {
        dao.add(new User("12"));
        dao.add(new User("123"));
    }
}
